
import Vue from '../node_modules/vue/dist/vue.js'
import app from "./App.vue"

import Mint from 'mint-ui';
import 'mint-ui/lib/style.css'; 

import './lib/mui/css/mui.min.css'
import './lib/mui/css/icons-extra.css'
import router from './router.js'
import  VueResource  from 'vue-resource'
import moment from  "moment"


import VuePreview from 'vue-preview'
 
import Vuex from 'vuex'

Vue.use(VuePreview)

Vue.use(VueResource) 
  
Vue.use(Vuex) 

Vue.filter("dateFormat",function(dataStr,pattern="yyyy-MM-dd HH:mm:ss"){
    return moment(dataStr).format(pattern)
})



Vue.use(Mint); 

var car=JSON.parse(localStorage.getItem("car")||"[]")

const store = new Vuex.Store({
    state: {
        car:car
    },
    mutations: {
        addToCar(state,goodsinfo){
            var flag=false;
            state.car.some(item=>{
                if(item.id=goodsinfo.id){
                    item.count+=parseInt(goodsinfo.count)
                    flag=true;
                    return true
                }
            })
            if(!flag){
                state.car.push(goodsinfo)
            }
            localStorage.setItem("car",JSON.stringify(state.car))
        },
        updateGoodsInfo(state,goodsinfo){
            state.car.some(item=>{
                item.count=parseInt(goodsinfo.id)
            })
        }
    },
    getters:{
        getAllCount(state){
            var c=0
            state.car.forEach(item=>{
                c+=item.count
            })
            return c
        },
        getGoodsCount(state){
            var o={}
            state.car.forEach(item=>{
                o[item.id]=item.count
            })
            return o
        },
        getGoodsSelected(state,id){
            var o={}
            state.car.forEach(item=>{
                o[item.id]=item.selected
            })
            return o
        }
    }
  })

var vm=new Vue({
    el:'#app',
    render:c=>c(app),
    router,
    store
})